package ltd.dujiabao.springcloud.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import ltd.dujiabao.springcloud.entities.CommonResult;
import ltd.dujiabao.springcloud.entities.Payment;
import ltd.dujiabao.springcloud.service.FeignPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author : DuJiabao
 * @Project : springcloud
 * @Time : 2021/5/22 17:10
 * @Desc :
 */
@Api("订单处理")
@Slf4j
@RestController
@RequestMapping("/feign")
public class OrderController {
  @Autowired
  FeignPaymentService feignPaymentService;

  @GetMapping("/payment/get/{id}")
  public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
    CommonResult<Payment> result = feignPaymentService.selectById(id);
    log.info("查询 id： " + id + "的结果为：" + result.toString());
    return result;
  }

  @PostMapping("/payment/create")
  public CommonResult createPayment(@RequestBody Payment payment) {
    CommonResult<Object> result = feignPaymentService.create(payment);
    log.info("插入数据：" + payment.toString());
    return result;
  }

  @GetMapping("/timeOut/{t}")
  CommonResult<Object> timeOut(@PathVariable("t") int t) {
    log.info("睡 " + t + "s");
    return feignPaymentService.timeOut(t);
  }
}
